package ${package.ServiceImpl};


import ${package.Mapper}.${table.mapperName};
import ${package.Entity}.${entity};
import ${package.Service}.${table.serviceName};

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.hsoft.zhxy.common.base.BaseService;
import com.hsoft.zhxy.common.result.ResultBody;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.List;

 /**
 * All rights Reserved, Designed By 哈尔滨工业大学软件工程股份有限公司
 * 
 * @Title: ${table.comment!} Service层接口实现类
 * @Package 
 * @Description: 
 * @author: ${author}
 * @date: ${date}
 */
@Log4j2
@Service
public class ${table.serviceImplName} extends BaseService implements ${table.serviceName} {

    @Autowired
    private ${table.mapperName} ${(table.mapperName)?uncap_first};


    /**
     * 查询单条数据
     * @param ${entity?uncap_first}
     * @return
     */
    @Override
    public JSONObject findOne(${entity} ${entity?uncap_first}) {
        ${entity} rs = ${(table.mapperName)?uncap_first}.selectOne(new QueryWrapper<${entity}>().setEntity(${entity?uncap_first}));
        return ResultBody.setData(rs);
    }


    /**
     * 查询列表数据
     * @param ${entity?uncap_first}
     * @return
     */
    @Override
    public JSONObject findList(${entity} ${entity?uncap_first}) {
        List<${entity}> list = ${(table.mapperName)?uncap_first}.selectList(new QueryWrapper<${entity}>().setEntity(${entity?uncap_first}));
        return ResultBody.setData(list);
    }


    /**
     * 查询分页数据
     * @param ${entity?uncap_first}
     * @param page
     * @param pageSize
     * @return
     */
    @Override
    public JSONObject findPageList(${entity} ${entity?uncap_first}, long page, long pageSize) {

        Page<${entity}> pageObj = new Page<${entity}>(page, pageSize);
        IPage<${entity}> result = ${(table.mapperName)?uncap_first}.selectPage(pageObj, new QueryWrapper<${entity}>().setEntity(${entity?uncap_first}));

        return ResultBody.setData(result.getTotal(), result.getRecords());
    }


    /**
     * 新增
     * @param ${entity?uncap_first}
     * @return
     */
    @Override
    public JSONObject add(${entity} ${entity?uncap_first}) {
        ${entity?uncap_first}.setCjsj(LocalDateTime.now());
        ${entity?uncap_first}.setCjr(getYhid());
        ${entity?uncap_first}.setBgsj(LocalDateTime.now());
        ${entity?uncap_first}.setBgr(getYhid());
        return ResultBody.setData(${(table.mapperName)?uncap_first}.insert(${entity?uncap_first}));
    }


    /**
     * 修改
     * @param ${entity?uncap_first}
     * @return
     */
    @Override
    public JSONObject update(${entity} ${entity?uncap_first}) {
        ${entity?uncap_first}.setBgsj(LocalDateTime.now());
        ${entity?uncap_first}.setBgr(getYhid());
        return ResultBody.setData(${(table.mapperName)?uncap_first}.updateById(${entity?uncap_first}));
    }


    /**
     * 删除
     * @param ${entity?uncap_first}
     * @return
     */
    @Override
    public JSONObject delete(${entity} ${entity?uncap_first}) {
        return ResultBody.setData(${(table.mapperName)?uncap_first}.delete(new QueryWrapper<${entity}>().setEntity(${entity?uncap_first})));
    }


}
